const defaultPre = 'hh-vue-base';

export default class Logger {
    private pre: string;
    private static logger: Logger


    static def(): Logger {
        if (!this.logger) {
            this.logger = new Logger()
        }
        return this.logger
    }

    constructor(pre: String | null = null) {
        this.pre = pre ? String(pre) : defaultPre;
    }

    v(data: any) {
        let str = typeof data === 'object' ? JSON.stringify(data) : String(data);
        console.log(`%c ${this.pre} %c${str}`, `background: #35495e; padding: 4px;color: #fff`,
            `background: #7f8c8d; padding: 4px; color: #fff;margin-left: 10px;`);
    }
    i(data: any) {
        let str = typeof data === 'object' ? JSON.stringify(data) : String(data);
        console.log(`%c ${this.pre} %c${str}`, `background: #35495e; padding: 4px;color: #fff`,
            `background: #1e90ff; padding: 4px; color: #fff;margin-left: 10px;`);
    }
    w(data: any) {
        let str = typeof data === 'object' ? JSON.stringify(data) : String(data);
        console.log(`%c ${this.pre} %c${str}`, `background: #35495e; padding: 4px;color: #fff`,
            `background: #f39c12; padding: 4px; color: #fff;margin-left: 10px;`);
    }
    e(data: any) {
        let str = typeof data === 'object' ? JSON.stringify(data) : String(data);
        console.log(`%c ${this.pre} %c${str}`, `background: #35495e; padding: 4px; color: #fff`,
            `background:red; padding: 4px; color: #fff;margin-left: 10px;`);
    }
}

